<template>
  <div>
    <el-dialog
      title="查看计量对象"
      :close-on-click-modal="false"
      :visible.sync="visible">
      <el-table
      :data="dataList"
      border
      :height="containerHeight"
      v-loading="dataListLoading"
      style="width: 100%;">
        <el-table-column prop="quotaName" label="指标名称"  align="center"></el-table-column>
        <el-table-column prop="quotaOType" label="计量类型"  align="center">
           <template slot-scope="scope">
            <span v-if="scope.row.quotaOType==1">设备</span>
            <span v-if="scope.row.quotaOType==2">区域</span>
            <span v-if="scope.row.quotaOType==3">部门</span>
          </template>
        </el-table-column>
        <el-table-column prop="normal" label="采集分类" minWidth="150" align="center">
          <template slot-scope="scope">
            {{ scope.row.collectType|statusName(meterTypeParamValueList)}}
          </template>
        </el-table-column>
        <el-table-column prop="monitorName" label="计量对象"  align="center"></el-table-column>

        <el-table-column prop="normal" label="额定值/增幅值"  align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.quotaType==0">额定值</span>
            <span v-if="scope.row.quotaType==1">增幅值</span>
          </template>
        </el-table-column>
        <el-table-column prop="upVal" label="上限"  align="center" v-if="ecsquotainfoData.quotaOType==1&&ecsquotainfoData.quotaType==0"></el-table-column>
        <el-table-column prop="downVal" label="下限"  align="center" v-if="ecsquotainfoData.quotaOType==1&&ecsquotainfoData.quotaType==0"></el-table-column>
        <el-table-column prop="addedVal" label="增幅值"  align="center" v-if="ecsquotainfoData.quotaType==1"></el-table-column>
        <el-table-column prop="routine_type" label="指标周期"  align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.quotaUnit==1">{{scope.row.quotaCycle}}(分钟)</span>
            <span v-if="scope.row.quotaUnit==2">{{scope.row.quotaCycle}}(小时)</span>
            <span v-if="scope.row.quotaUnit==3">{{scope.row.quotaCycle}}(天)</span>
            <span v-if="scope.row.quotaUnit==4">{{scope.row.quotaCycle}}(月)</span>
            <span v-if="scope.row.quotaUnit==5">{{scope.row.quotaCycle}}(年)</span>
          </template>
        </el-table-column>

    </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="visible = false">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import * as Util from "@/utils";
  // import Mixins from './unitSetting/unitSetting'
  export default {
    // mixins:[Mixins],
    data () {
      return {
        meterTypeParamValueList:[],
        visible: false,
        dataListLoading:false,
        dataList:[],
        ecsquotainfoData:{
          quotaOType:"",
          quotaType:'',
        }
      }
    },
    computed:{
      containerHeight() {
        return Util.getClientHeight() - 353;
      },
    },
    created(){
       this.querySubitem()
    },
    filters: {
      statusName: function (value,statusList) {
        for(let i=0;i<statusList.length;i++){
          if(statusList[i].collectType===value){
            return statusList[i].collectName;
          }
        }
      },
    },
    methods: {
      init (id) {
        this.visible = true
        this.$nextTick(() => {
          this.dataListLoading = true;
          this.dataList = [];
          this.$api.okhttp({
            url: this.$http.adornUrl(`/ecs/ecsquotainfo/info/${id}`),
            method: 'get',
            params: this.$http.adornParams(),
            customerId: this.$util.cookies.get("customer_id"),
            projectid:this.$util.cookies.get("cuuren_projectId")
          }).then((data) => {
            if (data && data.code === 0) {
              this.ecsquotainfoData = data.ecsquotainfo;
              if(data.ObjList&&data.ObjList.length>0){
                data.ObjList.forEach(element=>{
                  let dataInfo = JSON.parse(JSON.stringify(data.ecsquotainfo));
                  if(data.ecsquotainfo.quotaOType==1){
                    dataInfo.monitorName =  element.meterName;
                  }
                  else if(data.ecsquotainfo.quotaOType==2){
                    dataInfo.monitorName =  element.buildingName;

                  }
                  else if(data.ecsquotainfo.quotaOType==3){
                    dataInfo.monitorName =  element.organizationName;
                  }
                dataInfo.collectType =  element.collectType;
                  this.dataList.push(dataInfo);
                })
              }
            }
            this.dataListLoading = false;
          })
        })
      },
      querySubitem(meterType){
        //查询子分类
        this.queryCollectType(meterType,'0',data=>{
          if (data && data.code === 0) {
          this.meterTypeParamValueList = data.page.list
        } else {
          this.meterTypeParamValueList = [];
        }
      });
      },
      /**
       * 获取采集分项
       */
      queryCollectType(type,paramValue,callback) {
        let params = {
          'meterType': type ,
          'state': '1' ,
          'cumulativeType':paramValue,
          "customerId":this.$util.cookies.get('customer_id'),
          'page': 1,
          'limit': 10000,
        }
        this.$api.okhttp({
          url: this.$http.adornUrl('/ecs/ecscollectitem/list'),
          method: 'get',
          params: this.$http.adornParams(params)
        }).then((data) => {
          if(callback){
            callback(data);
          }
        });
      },
    }
  }
</script>

